package io.jee.medusa.orm.pager.utils;

import io.jee.medusa.orm.pager.output.DataGridPager;
import io.jee.medusa.orm.pager.output.OutputDatatablesPager;
import io.jee.medusa.orm.pager.output.OutputPager;
import io.jee.medusa.util.Pager;

public class PagerUtils {
	
	public static <T> OutputDatatablesPager<T> toDatatables(OutputPager<T> pager){
		OutputDatatablesPager<T> output = new OutputDatatablesPager<>();
		output.setRecordsTotal((int) pager.getTotal());
		output.setRecordsFiltered((int) pager.getTotal());
		output.setData(pager.getItems());
		return output;
	}
	
	public static <T> Pager<T> toPager(OutputPager<T> pager){
		Pager<T> output = new Pager<>();
		output.setTotal((int)pager.getTotal());
		output.setPageItems(pager.getItemSize());
		output.setData(pager.getItems());
		output.setOffset(pager.getIndex());
		return output;
	}
	
	public static <T> DataGridPager<T> toDataGrid(OutputPager<T> pager){
		DataGridPager<T> output = new DataGridPager<>();
		output.setTotal((int)pager.getTotal());
		output.setRows(pager.getItems());
		return output;
	}

}
